
#include <stdio.h>

#include <roboard.h>  // include this to use the RoBoIO library

int main(void) {

    // first set the correct RoBoard version
    //roboio_SetRBVer(RB_100);
    //roboio_SetRBVer(RB_100RD);  // if your RoBoard is RB-100RD
    roboio_SetRBVer(RB_110);    // if your RoBoard is RB-110
    //roboio_SetRBVer(RB_050);    // if your RoBoard is RB-050

    if (rcservo_Init(RCSERVO_USEPINS3) == false)  // set PWM/GPIO pins S3 as Servo mode
    {
        printf("ERROR: fail to init RC Servo lib (%s)!\n", roboio_GetErrMsg());
        return -1;
    }

    rcservo_EnterPWMMode();  // make all servo-mode pins go into PWM mode

    char input = 'c';
    bool dir = 1;
    while (input != 's')
    {
    	rcservo_OutPin(RCSERVO_PINS4, dir^=1 );
    	printf("Send PWM pulses of period 100us duty 30us on pin S3...\n");
    	rcservo_SendCPWM(RCSERVO_PINS3, 100L, 30L);

   
    	printf("Presss ENTER to change direction\nEnter 's' to stop.\n"); 
	input = getchar();
    }

    rcservo_StopPWM(RCSERVO_PINS3);

    rcservo_Close();  // close RC Servo lib
    return 0;
}

